package com.exonline.commons.utils;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

/**
 * @desc  获取文件上传的临时路径的工具类
 * @author hbrj
 */
public class PathsUtils {
    public static void main(String[] args) {
        System.out.println(getUploadPath());
    }

    /**
     * @desc  获取上传文件的临时路径
     * @return  上传文件的临时路径
     */
    public static String getUploadPath() {
        try {
            // 1. 获取 resources 目录下的 upload 文件夹路径
            ClassPathResource resource = new ClassPathResource("upload");
            File file = resource.getFile();
            Path uploadPath = file.toPath();
            // 2. 获取上传文件的临时路径
            System.out.println("upload 文件夹路径: " + uploadPath.toString());
            return uploadPath.toString();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("获取路径失败: " + e.getMessage());
        }
        return null;
    }

}